package de.iritgo.skillfull.component.visitor;

import java.awt.Dimension;

import de.iritgo.skillfull.component.motion.MoveFieldComponent;
import de.iritgo.skillfull.component.motion.PositionComponent;
import de.iritgo.skillfull.component.motion.RotationComponent;
import de.iritgo.skillfull.component.visual.AnimationRenderComponent;
import de.iritgo.skillfull.component.visual.ImageRenderComponent;
import de.iritgo.skillfull.component.visual.ShowPositionCordsComponentImpl;
import de.iritgo.skillfull.component.visual.SpriteSheetRenderComponent;

public class SimpleDefaultMotionVisitor extends BaseVisitor
{
	private Dimension dimension;
	private int x;
	private int y;
	private float rotation;
	private float scale;
	private int delta;
	
	public SimpleDefaultMotionVisitor (int delta)
	{
		this.delta = delta;
	}
	
	public void visit (PositionComponent positionComponent)	
	{	
		if (positionComponent.isRelative ())
		{
			x = x + (int) positionComponent.getX ();
			y = y + (int) positionComponent.getY ();
		}
		else	
		{
			x = (int) positionComponent.getX ();
			y = (int) positionComponent.getY ();
		}
	}
	
	public void visit (MoveFieldComponent moveFieldComponent) 
	{ 
		x = (int) moveFieldComponent.getX ();
		y = (int) moveFieldComponent.getY ();
	}

	public void visit (RotationComponent rotationComponent) 
	{ 
		rotationComponent.rotate (delta);
		rotation = rotationComponent.getRotation ();
	}

	public void visit (ImageRenderComponent renderComponent)
	{
		renderComponent.setRotation (rotation);
		renderComponent.setX (x);
		renderComponent.setY (y);
	}

	public void visit (AnimationRenderComponent animationRenderComponent)
	{
		animationRenderComponent.setRotation (rotation);
		animationRenderComponent.setX (x);
		animationRenderComponent.setY (y);
	}

	public void visit(SpriteSheetRenderComponent spriteSheetRenderComponent) 
	{ 
		spriteSheetRenderComponent.setRotation (rotation);
		spriteSheetRenderComponent.setX (x);
		spriteSheetRenderComponent.setY (y);
	}


	public void visit (ShowPositionCordsComponentImpl showPositionCordsComponentImpl) 
	{
		showPositionCordsComponentImpl.setX (x);
		showPositionCordsComponentImpl.setY (y);
	}
}
